<?php
/**
 * 输入处理类
 *
 * 处理输入参数，包括$_GET/$_POST/$_REQUEST/$_COOKIE
 * IP/浏览器/URI等参数
 *
 * @author fakis738@gmail.com
 * @link http://www.woophp.com/manual/class/input.lib.php
 * @version $id input.lib.php v0.1 2011-12-03$
 */
class Woo_Input
{
    protected $input = array();

    public function __construct($config)
    {
        $this->input['get'] = $_GET;
        $this->input['post'] = $_POST;
        $this->input['request'] = $_REQUEST;
        $this->input['cookie'] = $_COOKIE;
        $this->init();
    }

    /**
     * 初始化ipunt，过滤输入参数
     * @access protected
     * @return void
     */
    protected function init()
    {
        if(!get_magic_quotes_gpc())
        {
            $this->input = $this->addslashesDeep($this->input);
        }
    }

    /**
     * 使用递归，深度过滤
     * @access public
     * @param mix $value
     * @return string
     * @author fakis
     */
    public function addslashesDeep($value)
    {
        return is_array($value) ? array_map(array('self', 'addslashesDeep'), $value) : addslashes($value);
    }

    /**
     * $_GET 参数
     * @access public
     * @param string $key
     * @return string
     * @author fakis
     */
    public function G($key)
    {
        return isset($this->input['get'][$key]) ? $this->input['get'][$key] : '';
    }

    /**
     * $_POST 参数
     * @access public
     * @param string $key
     * @return string
     * @author fakis
     */
    public function P($key)
    {
        return isset($this->input['post'][$key]) ? $this->input['post'][$key] : '';
    }

    /**
     * $_REQUEST 参数
     * @access public
     * @param string $key
     * @return string
     * @author fakis
     */
    public function R($key)
    {
        return isset($this->input['request'][$key]) ? $this->input['request'][$key] : '';
    }

    /**
     * $_COOKIE 参数
     * @access public
     * @param string $key
     * @return string
     * @author fakis
     */
    public function C($key)
    {
        return isset($this->input['cookie'][$key]) ? $this->input['cookie'][$key] : '';
    }

    /**
     * 获取客户端IP
     * @access public
     * @return string
     * @author fakis
     */
    public function getIp()
    {
        return $_SERVER['REMOTE_ADDR'];
    }

    /**
     * 获取服务端IP
     * @access public
     * @return string
     * @author fakis
     */
    public function getServerIp()
    {
        return $_SERVER['SERVER_ADDR'];
    }

    /**
     * 获取客户端浏览器
     * @access public
     * @return string
     * @author fakis
     */
    public function getBrowser()
    {
    }

    /**
     * 获取访问URI
     * @access public
     * @return string
     * @author fakis
     */
    public function getUri()
    {
        return $_SERVER['REQUEST_URI'];
    }

    /**
     * 获取访问控制器
     * @access public
     * @return string
     * @author fakis
     */
    public function getController()
    {
    }

    /**
     * 获取访问方法
     * @access public
     * @return string
     * @author fakis
     */
    public function getMethod()
    {
    }
}
